package huaweiod.first;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * 华为OD机试真题 Java 实现【优雅子数组】【100%通过率】【2022.11 Q4 新题】
 */
public class A_2023_49_ElegantSubarray {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        int left = 0;
        int right = 0;
        Map<Integer, Integer> map = new HashMap<>();
        int count = 0;
        while (left < n && right < n) {
            map.put(arr[right], map.getOrDefault(arr[right], 0) + 1);
            if (map.get(arr[right]) >= k) {
                count = count + n - right;

                map.put(arr[left], map.get(arr[left]) - 1);
                left++;

                map.put(arr[right], map.get(arr[right]) - 1);
                right--;
            }
            right++;
        }
        System.out.println(count);
    }
}
